package ext;

import java.util.Map;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.kit.ResourceKit;
import com.jfinal.ext.route.AutoBindRoutes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.ykt.model.BftNotice;
import com.ykt.model.Customer;
import com.ykt.model.CustomerAddress;
import com.ykt.model.CustomerType;
import com.ykt.model.FileBox;
import com.ykt.model.FrontOrder;
import com.ykt.model.LoginLog;
import com.ykt.model.Menu;
import com.ykt.model.Order;
import com.ykt.model.OrderDetail;
import com.ykt.model.PaymentOrder;
import com.ykt.model.Postage;
import com.ykt.model.Product;
import com.ykt.model.ProductImg;
import com.ykt.model.ProductType;
import com.ykt.model.Role;
import com.ykt.model.Shop;
import com.ykt.model.ShopType;
import com.ykt.model.TempCart;
import com.ykt.model.User;

public class Config extends JFinalConfig{

	@Override
	public void configConstant(Constants me) {
		// TODO Auto-generated method stub
		//this.getClass().getClassLoader().getResourceAsStream("jdbc.txt");
		me.setDevMode(true);
	}

	@Override
	public void configRoute(Routes me) {
		// TODO Auto-generated method stub
		AutoBindRoutes ab =new AutoBindRoutes();
		ab.autoScan(false);
		me.add(ab);
	}

	@Override
	public void configPlugin(Plugins me) {
		// TODO Auto-generated method stub
		Map<String,String> conf=ResourceKit.readProperties("jdbc.txt");
		C3p0Plugin c3p0Plugin = new C3p0Plugin(conf.get("jdbcUrl"),conf.get("user"), conf.get("password").trim());
		
		//new C3p0Plugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password").trim());
		me.add(c3p0Plugin);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		arp.addMapping("user", User.class);
		arp.addMapping("product", Product.class);
		arp.addMapping("product_type", ProductType.class);
		arp.addMapping("product_img", ProductImg.class);
		arp.addMapping("front_order", FrontOrder.class);
		arp.addMapping("customer", Customer.class);
		arp.addMapping("filebox", FileBox.class);
		arp.addMapping("login_log", LoginLog.class);
		arp.addMapping("shop", Shop.class);
		arp.addMapping("shop_type", ShopType.class);
		arp.addMapping("customer_address", CustomerAddress.class);
		
		arp.addMapping("customer_type", CustomerType.class);
		arp.addMapping("orders", Order.class);//订单表
		arp.addMapping("order_detail", OrderDetail.class);
		arp.addMapping("postage", Postage.class);//邮费表
		arp.addMapping("payment_order", PaymentOrder.class);//支付订单
		arp.addMapping("bft_notice", BftNotice.class);//支付详情
		
		arp.addMapping("temp_cart", TempCart.class);//临时购物车表，商户代客下单时使用
		
		arp.addMapping("menu", Menu.class);//临时购物车表，商户代客下单时使用
		arp.addMapping("role", Role.class);//临时购物车表，商户代客下单时使用
		
		arp.setDevMode(true);
		arp.setShowSql(true);
		me.add(arp);
		
		
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub
	}

	@Override
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub
        me.add(new ContentHandlers());
		
	}

}
